#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
using LL = long long;
using PLL = pair<LL, LL>;

PLL calc(LL n, LL m){   // 在第n级城市编号为m的位置
    if(n == 0) return {0, 0};
    LL len = 1ll << (n - 1), cnt = 1ll << (2 * n - 2);
    PLL temp = calc(n - 1, m % cnt);
    LL x = temp.first, y = temp.second;
    LL k = m / cnt;
    if(k == 0){
        return {y, x};
    }
    
    if(k == 1){
        return {x, y + len};
    }
    
    if(k == 2){
        return {x + len, y + len};
    }
    
    return {2 * len - y - 1, len - x - 1};
}


int main(){
    int T;
    cin >> T;
    while(T--){
        LL n, a, b;
        cin >> n >> a >> b;
        PLL t1 = calc(n, a - 1), t2 = calc(n, b - 1);
        LL d1 = abs(t1.first - t2.first), d2 = abs(t1.second - t2.second);
        
        double res = 10 * sqrt(d1 * d1 + d2 * d2);
        printf("%.0lf\n", res);
    }
    return 0;
}